package com.newsmanagement.config;


import com.newsmanagement.utils.AliOssUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 配置类：用于创建AliOssUtil
 */
@Configuration
@Slf4j
public class OssConfiguration {


    /**
     * 创建AliOssUtil交给IOC容器管理
     * 因为他是要使用这个工具类进行文件上传
     * @param aliOssProperties
     * @return
     */
    @Bean
    @ConditionalOnMissingBean//保证在IOC容器中只有一个此对象
    public AliOssUtil aliOssUtil(AliOssProperties aliOssProperties){
        log.info("开始创建阿里云文件上传工具类对象：{}",aliOssProperties);
        return new AliOssUtil(aliOssProperties.getEndpoint(),
                aliOssProperties.getAccessKeyId(),
                aliOssProperties.getAccessKeySecret(),
                aliOssProperties.getBucketName());
    }


}
